# coding=utf-8
import csv
import os
import sys
from pathlib import Path


class TechCsvProcess():
    def __init__(self,Tech_csv_path= os.path.join(Path(__file__).parent.parent,"Assets/Tech/Tech.csv")):
    
        self.Tech_csv_path = Tech_csv_path
        self.contentArray = []
        # print("+++++++++++++++++++++++=")
        # print(self.Tech_csv_path)
        self.getCsvContent()

    def getCsvContent(self):
        Tech_csv_path = self.Tech_csv_path
    
        with open(Tech_csv_path,encoding = "utf-8-sig",mode = "r") as f:
            dictReader = csv.DictReader(f)
            
            TestName_Flag = ""
            for row in dictReader:
                perLineDic = {}
                
                if row["TestName"] != None and row["TestName"] != "":
                    TestName_Flag = row["TestName"]

                perLineDic["TestName"] = TestName_Flag
                perLineDic["TestActions"] = row["TestActions"]
                perLineDic["Disable"] = row["Disable"]
                perLineDic["Input"] = row["Input"]
                perLineDic["Output"] = row["Output"]
                perLineDic["Timeout"] = row["Timeout"]
                perLineDic["Retries"] = row["Retries"]
                perLineDic["AdditionalParameters"] = row["AdditionalParameters"]
                perLineDic["ExitEarly"] = row["ExitEarly"]
                perLineDic["SetPoison"] = row["SetPoison"]
                perLineDic["Commands"] = row["Commands"]
                perLineDic["FA"] = row["FA"]
                perLineDic["Condition"] = row["Condition"]
                perLineDic["CondNotesition"] = row["Notes"]
                self.contentArray.append(perLineDic)
        
        return self.contentArray

    # 根据TestName从Tech中取出要测试测试项 
    def getCsvTechContent(self,TestName):
        contentDict = {}
        # Tech_csv_parent_directory = os.path.abspath(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
        # Tech_csv_path = os.path.join(Tech_csv_parent_directory,"Assets/Tech/DUTInfo.csv")
        # Tech_csv_path = os.path.join(Tech_csv_parent_directory,"Assets/Tech/"+Tech+".csv")
        list = []
        # print(self.contentArray)
        for perLineDic in self.contentArray:
                if perLineDic["TestName"] == TestName:
                    list.append(perLineDic)
        contentDict = {
                TestName:list
        }
        # print(contentDict)
        return contentDict


if __name__ == "__main__":
    getTech = TechCsvProcess(os.path.join(Path(__file__).parent.parent,"Assets/Tech/Tech.csv"))
    print(getTech.getCsvTechContent('Reset#Delay500ms01'))
    # print(TechCsvProcess.getCsvTechContent("CommandsWithOneVariable"))

